package com.hanbang.baseproject.view.home.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.EditText;

import com.hanbang.baseproject.R;
import com.hanbang.baseproject.code.base.view.activity.BaseActivity;
import com.hanbang.baseproject.utils.other.EditHelper;

import butterknife.BindView;


/**
 * 类说明:
 * 2017/5/3  13:03
 */

public class EditActivity extends BaseActivity {
    public EditHelper editHelper = new EditHelper(this);
    String title;

    @Override
    public int getContentView() {
        return R.layout.activity_edit;
    }


    /**
     * 返回到当前页
     *
     * @param context
     * @param title
     */
    public static void startUI(Activity context, String title, int request) {
        Intent intent = new Intent(context, EditActivity.class);
        intent.putExtra("title", title);
        context.startActivityForResult(intent,request);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void parseIntent(Intent intent) {
        title = intent.getStringExtra("title");
    }

    /*
     * 初始化view
     */
    public void initView() {
        toolbar.setTitle(title);
        toolbar.setBack(this);
        toolbar.addAction(1, "保存");
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                if (editHelper.check()) {
                    Intent intent = new Intent();
                    intent.putExtra("content", loginName.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }
                return false;
            }
        });

//        editHelper.addEditHelperData(new EditHelper.EditHelperData(loginName, Validators.getLenghMinRegex(1), "内容不能为空"));


    }


    @BindView(R.id.login_name)
    EditText loginName;


}
